package com.todo.strategy.pipeline.application.api.controller;

import com.todo.common.common.entity.response.BizResponse;
import com.todo.strategy.pipeline.application.entity.bo.TransferOriginDataBO;
import com.todo.strategy.pipeline.application.service.PipelineService;
import com.todo.strategy.pipeline.service.api.DataExecuteApi;
import com.todo.strategy.pipeline.service.api.request.OfflineToOnlineRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2025/3/1 22:57
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/api/pipeline/execute")
@Tag(name = "服务端-备忘录模板同步接口", description = "服务端-备忘录模板同步接口")
public class DataExecuteApiController implements DataExecuteApi {

    @Resource
    private PipelineService pipelineService;


    @Override
    @Operation(summary = "离线到线上数据同步")
    @PostMapping("/offlineToOnline")
    public BizResponse<Boolean> offlineToOnline(OfflineToOnlineRequest request) {
        TransferOriginDataBO transferOriginDataBO = new TransferOriginDataBO();
        transferOriginDataBO.setUniKey(request.getUniKey());
        transferOriginDataBO.setStrategyActionEnum(request.getStrategyActionEnum());
        transferOriginDataBO.setOperateActionEnum(request.getOperateActionEnum());
        transferOriginDataBO.setBusinessId(request.getBusinessId());
        transferOriginDataBO.setOriginData(request.getOriginData());
        transferOriginDataBO.setEnableVersion(request.getEnableVersion());
        transferOriginDataBO.setCurrentVersion(request.getCurrentVersion());
        Boolean updated = pipelineService.transferOriginData(transferOriginDataBO);
        return BizResponse.success(updated);
    }

    @Override
    @Operation(summary = "离线到线上数据同步异步")
    @PostMapping("/offlineToOnlineAsync")
    public BizResponse<Boolean> offlineToOnlineAsync(OfflineToOnlineRequest request) {
        TransferOriginDataBO transferOriginDataBO = new TransferOriginDataBO();
        transferOriginDataBO.setUniKey(request.getUniKey());
        transferOriginDataBO.setStrategyActionEnum(request.getStrategyActionEnum());
        transferOriginDataBO.setOperateActionEnum(request.getOperateActionEnum());
        transferOriginDataBO.setBusinessId(request.getBusinessId());
        transferOriginDataBO.setOriginData(request.getOriginData());
        transferOriginDataBO.setEnableVersion(request.getEnableVersion());
        transferOriginDataBO.setCurrentVersion(request.getCurrentVersion());
        Boolean updated = pipelineService.transferOriginDataAsync(transferOriginDataBO);
        return BizResponse.success(updated);
    }
}
